﻿using System;
using System.Collections.Generic;
using System.IO;
using Windows.UI.Xaml.Media.Imaging;
using System.Linq;
using System.Windows.Input;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Input;
using Windows.UI.Core;
using System.Threading;
using System.Collections.Concurrent;

namespace RoboRun
{
    class drawInPosition
    {
        public static void drawInPosition4x4(Image image, String startingPosition,float offset)
        {
            Image RobotSprite = GameplayScreen.RobotSpriteRef;
            float width = GameplayScreen.width;
            float height = GameplayScreen.height;
            //Depending on level info, sprite is drawn in position specified

            try
            {
                if (startingPosition.Equals("2,1"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 768 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = offset + 244 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(768 * width / 1920, offset + 244 * height / 1080, 0, 0);

                }
                else  if (startingPosition.Equals("2,2"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1051 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = offset + 244 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1051 * width / 1920, offset + 244 * height / 1080, 0, 0);

                }
                else if (startingPosition.Equals("1,1"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 768 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = offset + 0 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(768 * width / 1920, offset + 0 * height / 1080, 0, 0);

                }
                else if (startingPosition.Equals("1,2"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1051 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = offset + 0 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1051 * width / 1920, offset + 0 * height / 1080, 0, 0);

                }
                else if (startingPosition.Equals("1,3"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1342 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = offset + 0 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1342 * width / 1920, offset + 0 * height / 1080, 0, 0);
                }
                else if (startingPosition.Equals("1,4"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1630 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = offset + 0 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1630 * width / 1920, offset + 0 * height / 1080, 0, 0);
                }
                else if (startingPosition.Equals("3,1"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 768 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = (offset / 2) + 515 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(768 * width / 1920, (offset / 2) + 515 * height / 1080, 0, 0);
                }
                else if (startingPosition.Equals("3,2"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1051 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = (offset / 2) + 515 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1051 * width / 1920, (offset / 2) + 515 * height / 1080, 0, 0);
                }
               
                else if (startingPosition.Equals("2,3"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1342 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = offset + 244 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1342 * width / 1920, offset + 244 * height / 1080, 0, 0);
                }

                else if (startingPosition.Equals("2,4"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1630 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = offset + 244 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1630 * width / 1920, offset + 244 * height / 1080, 0, 0);
                }
                else if (startingPosition.Equals("4,1"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 768 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = 809 * height / 1080 - (offset / 2);
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(768 * width / 1920, 809 * height / 1080 - (offset / 2), 0, 0);
                }
                else if (startingPosition.Equals("4,2"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1051 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = 809 * height / 1080 - (offset / 2);
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1051 * width / 1920, 809 * height / 1080 - (offset / 2), 0, 0);
                }
                else if (startingPosition.Equals("4,3"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1342 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = 809 * height / 1080 - (offset / 2);
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1342 * width / 1920, 809 * height / 1080 - (offset / 2), 0, 0);
                }
                else if (startingPosition.Equals("4,4"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1630 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = 809 * height / 1080 - (offset / 2);
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1630 * width / 1920, 809 * height / 1080 - (offset / 2), 0, 0);
                }
                else if (startingPosition.Equals("3,3"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1342 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = (offset / 2) + 515 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1342 * width / 1920, (offset / 2) + 515 * height / 1080, 0, 0);
                }
                else if (startingPosition.Equals("3,4"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1630 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = (offset / 2) + 515 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1630 * width / 1920, (offset / 2) + 515 * height / 1080, 0, 0);
                }
            }
            catch (NullReferenceException)
            {
                return;
            }
        }

        public static void drawInPosition3x3(Image image, String startingPosition, float offset)
        {
            Image RobotSprite = GameplayScreen.RobotSpriteRef;
            float width = GameplayScreen.width;
            float height = GameplayScreen.height;
            //Depending on level info, sprite is drawn in position specified

            try
            {
                if (startingPosition.Equals("1,1"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 810 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = offset + 20 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(810 * width / 1920, offset + 20 * height / 1080, 0, 0);

                }
                else if (startingPosition.Equals("1,2"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1192 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = offset + 20 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1192 * width / 1920, offset + 20 * height / 1080, 0, 0);

                }
                else if (startingPosition.Equals("1,3"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1584 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = offset + 20 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1584 * width / 1920, offset + 20 * height / 1080, 0, 0);
                }
                else if (startingPosition.Equals("2,1"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 810 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = (offset / 2) + 380 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(810 * width / 1920, (offset / 2) + 380 * height / 1080, 0, 0);
                }
                else if (startingPosition.Equals("2,2"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1192 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = (offset / 2) + 380 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1192 * width / 1920, (offset / 2) + 380 * height / 1080, 0, 0);
                }
                else if (startingPosition.Equals("2,3"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1584 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = (offset / 2) + 380 * height / 1080;
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1584 * width / 1920, (offset / 2) + 380 * height / 1080, 0, 0);
                }
                else if (startingPosition.Equals("3,1"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 810 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = 770 * height / 1080 - (offset / 2);
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(810 * width / 1920, 770 * height / 1080 - (offset / 2), 0, 0);
                }

                else if (startingPosition.Equals("3,2"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1192 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = 770 * height / 1080 - (offset / 2);
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1192 * width / 1920, 770 * height / 1080 - (offset / 2), 0, 0);
                }
                
                else if (startingPosition.Equals("3,3"))
                {
                    if (image.Equals(RobotSprite))
                    {
                        GameplayScreen.robotSpriteMargin.Left = 1584 * width / 1920;
                        GameplayScreen.robotSpriteMargin.Top = 770 * height / 1080 - (offset / 2);
                        GameplayScreen.robotSpriteMargin.Bottom = 0;
                        GameplayScreen.robotSpriteMargin.Right = 0;
                    }
                    image.Margin = new Thickness(1584 * width / 1920, 770 * height / 1080 - (offset / 2), 0, 0);
                }
            }
            catch (NullReferenceException)
            {
                return;
            }
        }
    }
}
